#include "DirectorTangShi.h"

#include "UI/ModRun/Output/FactoryOutput.h"

DirectorTangShi::DirectorTangShi()
{
    m_listFood.clear();

    QString strOutput = "指挥者堂食 构造:";
    qDebug() << strOutput;
    std::shared_ptr<IOutput> pOutPut = FactoryOutput::GetInstance()->CreateRunOutput();
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutput };
        pOutPut->OutPut(outList);
    }
}

DirectorTangShi::~DirectorTangShi()
{
    QString strOutput = "指挥者堂食 析构:";
    qDebug() << strOutput;
    std::shared_ptr<IOutput> pOutPut = FactoryOutput::GetInstance()->CreateRunOutput();
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutput };
        pOutPut->OutPut(outList);
    }
}

void DirectorTangShi::directFoods(std::shared_ptr<InterFaceFoodBuilder> builder, size_t uNum)
{
    QString strOutputStart = "--------指挥者堂食 Direct产品开始-------:";
    qDebug() << strOutputStart;
    std::shared_ptr<IOutput> pOutPut = FactoryOutput::GetInstance()->CreateRunOutput();
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutputStart };
        pOutPut->OutPut(outList);
    }
    /////////////////////////////////////////////////////////////////////////
    for (size_t i = 0; i < uNum; i++)
    {
        if (builder)
        {
            builder->CreateFood(uNum);
            std::list<std::shared_ptr<IFood>> listAppend = builder->GetFoodItems();
            //将生成food加入到食物列表;
            m_listFood.insert(m_listFood.end(), listAppend.begin(), listAppend.end());
        }
    }
    //////////////////////////////////////////////////////////////////////

    QString strOutputEnd = "--------指挥者堂食 Direct产品结束---------:";
    qDebug() << strOutputEnd;
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutputEnd };
        pOutPut->OutPut(outList);
    }
}

std::list<std::shared_ptr<IFood>> DirectorTangShi::GetComboItems()
{
    QString strOutputStart = "**********指挥者堂食 打印产品开始:**********";
    qDebug() << strOutputStart;
    std::shared_ptr<IOutput> pOutPut = FactoryOutput::GetInstance()->CreateRunOutput();
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutputStart };
        pOutPut->OutPut(outList);
    }

    for(std::shared_ptr<IFood> &food : m_listFood)
    {
        if (food)
        {
            qDebug() << food->GetFoodName();
            if (pOutPut)
            {
                std::initializer_list<QString> outList{ food->GetFoodName() };
                pOutPut->OutPut(outList);
            }
        }
    }

    QString strOutputEnd = "**********指挥者堂食 打印产品结束:**********";
    qDebug() << strOutputEnd;
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutputEnd };
        pOutPut->OutPut(outList);
    }
    return m_listFood;
}
